<template>
  <div>
    <Search :mess="mess" />
    <!-- 分类页面 --> 
    <van-tree-select
      :items="types"
      height="100vh"
      :main-active-index="activeindex"
      :active-id="rightid"
      @click-nav="leftfn"
      ref="right"
    >
      <template #content>
        <div ref="right">
          <div v-for="(item, index) in contentsright" :key="index">
            <img :src="item.image" alt="" />
            <h3>{{ item.text }}</h3>
          </div>
        </div>
      </template>
    </van-tree-select>
    <tab-bar></tab-bar>
  </div>
</template>
<script>
import TabBar from "../components/TabBar.vue";
import Search from "@/components/Search.vue";
import instance from "@/api/api";
export default {
  name: "type",
  data() {
    return {
      mess: "分类页搜索",
      types: [], //存放请求数据
      activeindex: 0, //左侧默认选中字段
      rightid: "", //右侧选中的id
      contentsright: [], //右侧数据
    };
  },
  methods: {
    leftfn(item) {
      // 点击左侧导航触发的事件
      console.log(item); //点击当前的索引
      this.activeindex = item;
      this.contentsright = this.types[item].children;
      // 获取右侧元素
      //  console.log(this.$refs,right[item])
      //  let right = this.$refs
      var xx = document.getElementsByClassName("van-tree-select__content");
      xx[0].scrollTop = 0;
      console.log(xx[0].scrollTop);
    },
    async gettypes() {
      // 请求数据的函数
      let { data } = await instance.get("/type");
      console.log(data);
      this.types = data;
    },
  },
  created() {
    this.gettypes();
  },
  components: {
    TabBar,
    Search,
  },
};
</script>
<style lang="less" scoped>
.van-sidebar::-webkit-scrollbar {
  display: none;
}
.van-tree-select__content::-webkit-scrollbar {
  display: none;
}
</style>